﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FightUIMgr : BaseManager<FightUIMgr>
{
    //摇杆
    Joystick _joystick;
    TouchScene _touchScene;


    //技能按钮
    SkillAtkDlg _skillAtkDlg;
    //人物头像
    TargetHead _targetHead;
    //小地图
    //目标头像
    //功能大厅
    FunctionHall _functionHall;

    
    public void Init()
    {
        if (_joystick == null)
        {
            _joystick = new Joystick();

        }
        if (_touchScene == null)
        {
            _touchScene = new TouchScene();
            // Debug.Log("touchScene");
        }
        if(_functionHall == null)
        {
            _functionHall = new FunctionHall();
        }
        if (_targetHead == null)
        {
            _targetHead = new TargetHead();
            _targetHead.Hide();
        }
        if(_skillAtkDlg == null)
        {
            _skillAtkDlg = new SkillAtkDlg();
        }
    }

    public void BindingJoystick(Action<Vector2> OnMoveDir, Action OnMoveEnd)
    {
        if (_joystick == null) { return; }
        _joystick.OnMoveDrag = OnMoveDir;
        _joystick.OnMoveEnd = OnMoveEnd;
    }
    public void BindingTouchScene(Action<RaycastHit> onTouchSth, int layer)
    {
        //if (_touchScene == null) { return; }
        _touchScene.UnTouchLayer = layer;
        _touchScene.HiStnCallback = onTouchSth;
    }
    public void BindingSkillBtn(Action<int> skillBtnCallback,Func<int,float>getSkillCDCallback)
    {
        if (_skillAtkDlg == null) { return; }
        _skillAtkDlg.OnSkillBtnClick = skillBtnCallback;
        _skillAtkDlg.OnGetSkillCD = getSkillCDCallback;
    }

    public void SetTargetActive(bool bActive)
    {
        if (bActive)
        {
            _targetHead.Show();
        }
        else
        {
            _targetHead.Hide();
        }
    }

    public void SetTargetInfo(string name,int curHp,int maxHp,bool bActive=true)
    {
        SetTargetActive(true);
        _targetHead.SetTargetInfo(name, curHp, maxHp, bActive);
    }

  
    private void ReleaseTouchScene()
    {
        if (_touchScene == null) { return; }
        _touchScene.HiStnCallback = null;
       
    }

    private void ReleaseJoystick()
    {
        if (_joystick == null) { return; }
        _joystick.OnMoveDrag = null;
        _joystick.OnMoveEnd = null;

    }
  
    private void resetJoystick()
    {
        if (_joystick == null) { return; }
        _joystick.Reset();
    }
    private void resetSkillAtkDlg()
    {
        if (_skillAtkDlg == null) { return; }
        _skillAtkDlg.OnSkillBtnClick = null;
    }

    private void resetTargetHead()
    {
        if (_targetHead == null) { return; }
        _targetHead.Hide();
    }
    public void Reset()
    {
        ReleaseJoystick();
        ReleaseTouchScene();
        resetJoystick();
        resetTargetHead();
        resetSkillAtkDlg();
    }

 
}
